<?php
$t = 360;//缓存时间，单位：秒
if(!is_file('fetch.html')||(time()-filemtime('fetch.html'))>$t){
$qq = 'wait4you';
$user=$_GET['user'];
$pwd = 'XXXXXXXXXXXXXXXXXXXX';//换成你自己的MD5_3后的密码
//调用方式：weibo.php?user=XXX,XXX为你的围脖用户名，注意不是你的QQ号
$verifyURL = 'http://ptlogin2.qq.com/check?uin=@'.$qq.'&appid=46000101';
$loginURL = 'http://ptlogin2.qq.com/login?';
 //获取验证码及第一次cookie
$curl=curl_init($verifyURL);
$cookie_jar = tempnam('.', 'cookie');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
$verifyCode = curl_exec($curl);
curl_close($curl);
$verifyCode = strtoupper(substr($verifyCode, 18, 4));

 
//发送登录请求并获取第二次cookie
$loginURL .= 'u=@'.$qq.'&p='.md5($pwd.$verifyCode).'&verifycode='.$verifyCode.'&aid=46000101&u1=http%3A%2F%2Ft.qq.com&h=1&from_ui=1&fp=loginerroralert';
//echo '登录地址：'.$loginURL;
//echo '<hr />';
$curl = curl_init($loginURL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
$loginResult = curl_exec($curl);
curl_close($curl);

 
//获取第三次cookie
$curl = curl_init('http://t.qq.com');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
$loginResult = curl_exec($curl);
curl_close($curl);
 
//第四次
$curl = curl_init('http://t.qq.com/'.$user.'/mine');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
$loginResult = curl_exec($curl);
curl_close($curl);
unlink($cookie_jar);
file_put_contents('fetch.html',$loginResult);
}
@header('Content-type: text/html; charset=utf-8');
if(is_file("fetch.html")){
$content=file_get_contents("fetch.html");
$pattern="~<div class=\"msgBox\">.*<div class=\"pubInfo\">~isU";
 preg_match_all($pattern,$content,$match);
 //print_r($match);//所有记录
 //echo '<hr>';
$message1=$match[0][0];//暂只抓取第一条信息
$message1=str_replace('href="/','href="http://t.qq.com/',$message1);
$message1=strip_tags($message1,'<a>');
$m2=addslashes($message1);
echo 'document.writeln("'.$m2.'");';
//echo '<hr>';
//print_r($message1);
}else{
	die('参数错误或者服务器不支持CURL');
}
?>